// vant 懒加载
// https://www.cnblogs.com/love314159/p/13631267.html
const merge = require("webpack-merge");
const tsImportPluginFactory = require("ts-import-plugin");

// 开启gzip
//https://blog.csdn.net/weixin_38988990/article/details/115152676
const CompressionWebpackPlugin = require("compression-webpack-plugin");

module.exports = {
    publicPath: './',
    lintOnSave:false,
    parallel: false,
    devServer: {
        overlay: {
            warnings: false, //不显示警告
            errors: false,//不显示错误
        },
        proxy: {
            '/wxapi': {
                target: 'https://xxxxxx/wxapi',
                changeOrigin: true,
                pathRewrite: {
                    '^/wxapi': '' // 重写url，将url中的 '/api' 替换掉
                }
            }
        }
    },
    css:{
      requireModuleExtension:true
    },
    productionSourceMap: false,
    chainWebpack: config => {
      config.module
        .rule("ts")
        .use("ts-loader")
        .tap(options => {
          options = merge(options, {
            transpileOnly: true,
            getCustomTransformers: () => ({
              before: [
                tsImportPluginFactory({
                  libraryName: "vant",
                  libraryDirectory: "es",
                  style: true
                })
              ]
            }),
            compilerOptions: {
              module: "es2015"
            }
          });
          return options;
        });
    },
    configureWebpack: {
        plugins: [
            new CompressionWebpackPlugin({
                filename: '[path].gz[query]',
                algorithm: 'gzip',
                test: new RegExp('\\.(js|css)$'),
                // 10kb
                threshold: 10240,
                minRatio: 0.8
            })
        ],
    }
}
